import { PIC_URL } from './../../providers/Config';
import { nailerService } from './../../providers/nailerService';
import { Component, Injector } from '@angular/core';
import { NavController } from 'ionic-angular';
import { IonicPage } from 'ionic-angular';
import { BasePage } from "../basePage";
import { StorageService } from '../../providers/StorageService';


// import { NoteDetailPage } from './note-detail/note-detail';
declare var $:any;

@IonicPage({ name: "contact" })
@Component({
  selector: 'page-contact',
  templateUrl: 'contact.html'
})
export class ContactPage extends BasePage {
  article="0";
  userinfo={}
  /**获取文章列表参数 */
  param = {
    page_size:6,
    article_type:'',
    page_pos:0
  };
  picrooturl = '';//图片服务器的地址

  /*文章列表数据 */
  textList=[];
  flag:string = "0";
  
  searchObj = {
    content:'',
    article_type:'0'
  }

  haveId:boolean;   //无身份隐藏悬浮按钮
  constructor(injector: Injector,private nailerservice:nailerService,public storage: StorageService,) {
    super(injector);
    this.picrooturl = PIC_URL;
    this.userinfo = this.storage.read('userinfo');
  }
  ionViewDidLoad() {
   
  }
  /**每当进入页面执行 */
  ionViewWillEnter(){
    this.getText(this.article);
    if(this.userinfo==null){
      this.haveId=false;
    }else{
      this.haveId=true;
    }
  }
  /**点击帖子跳转到帖子详情页面 */
  goDetail(text_id,presenter_id) {
    // if(this.userinfo == null){
    //   this.showAlert("您当前未登录，请登录后操作！")
    // }else{
      this.navCtrl.push("NoteDetailPage",{txt_id:text_id,presenter_id:presenter_id})
    // }
  }

   /**下拉刷新 */
   doRefresh(refresher) {
    console.log(refresher);
    console.log("下拉刷新");
    this.getText(this.article);
    setTimeout(() => {
      console.log("加载完成后，关闭刷新");
      refresher.complete();
      let toast = this.toastCtrl.create({
        message: "刷新完成",
        duration: 1500
      });
      toast.present();
    }, 2000);
  }

 
  /**点击发布帖子 */
  publish(){
    this.navCtrl.push("NotePubPage");
  }
  fo(index){
    $(".nav li i").css("display","none");
    $(".nav li i").eq(index).css("display","block");
  }
  /**获取文章列表 */
  async getText(index){

      console.log(this.flag);
      this.article = index;
      this.param.article_type = index;
      this.searchObj.article_type = index;
      console.log(this.param);
      let res = await this.nailerservice.getTextList(this.param);
      if(res.data){
        this.textList = res.data;
        console.log(this.textList);
      }
     
      this.fo(index);
  }
  doInfinite(){
    this.param.page_pos = this.param.page_pos +1;
    this.getText(0);
  }
 /**搜索文章 */
 async searchArticle(e){
   console.log(this.searchObj);
   let res = await this.nailerservice.searchArticle(this.searchObj);
   console.log(res);
   if(res.data){
    this.textList = res.data;
   }
  
 }

  //跳转到发布
  add1() {
     let modal = this.modalCtrl.create("AddPage");
     modal.present();
    // this.navCtrl.push("AddPage")
  }
}
